class Solution
{
public:
    vector<int> productQueries(int n, vector<vector<int>> &queries)
    {
        vector<long long> powers;
        long long p = 1;
        while (n)
        {
            if (n & 1)
            {
                powers.push_back(p);
            }
            n = n >> 1;
            p = p << 1;
        }

        vector<int> result;
        for (auto &query : queries)
        {
            long long product = 1;
            for (int i = query[0]; i <= query[1]; ++i)
            {
                product *= powers[i];
                product %= 1000000007LL;
            }
            result.push_back(product);
        }
        return result;
    }
};